#pragma once

#include "..\Type\Permission.h"
#include "..\Type\Province.h"
#include "..\Type\User.h"
#include "../Type\UserInfo.h"

namespace TCServer
{
    namespace Manager
    {
        class UserManager
        {
        public:
            class LoginResult
            {
            public:
                bool success;
                QByteArray signature;
                QSet<Type::Permission> permissons;
            };
        private:
            UserManager();
        public:
            ~UserManager();
        public:
            // Methods for Client & Server

            /* login with username and password
             **/
            LoginResult login(const QString &username, const QString &password);

            /* login with user id */
            LoginResult login_with_id(quint64 userId);
            bool usernameExist(const QString &username);
            bool emailExist(const QString &email);
            bool phoneExist(const QString &phone);
            void registerWithUsername(const QString &username, const QString &password);
            void registerWithEmail(const QString &email, const QString &password);
            void registerWithPhone(const QString &phone, const QString &password);

            Type::User queryUser(quint64 userId);
            bool changeUser(const Type::User &newval);
            Type::UserInfo queryInfo(quint64 userId);
            bool changeInfo(const Type::UserInfo &newInfo);

        private:
            Type::User createDefaultUser();

        public:
            static UserManager* instance();
        };
    }
}